home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 376_04 / os2tool.003 / UPTIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-29  |  2.8 KB  |  120 lines

  1. /*
  2. * UPTIME.C - Show the time the system has been running.
  3. *
  4. * PROGRAMMER:        Martti Ylikoski
  5. * CREATED:        30.3.1991
  6. */
  7. static char *VERSION = "Versio 1.0, Copyright (c) Martti Ylikoski, 1991" ;
  8. /*
  9. */
  10.  
  11. #include <stdio.h>
  12. #define INCL_DOSINFOSEG
  13. #include <os2.h>
  14. #include <param.h>
  15. #include <paramstd.h>
  16.  
  17. static char *progname, *fname    ;
  18. extern unsigned long pflags ;
  19.  
  20. ParamEntry pentry[12] = {
  21.      "P", &ParamSetPause, 0,
  22.      "F", &ParamSetFold, 0,
  23.      "V", &ParamSetVerbose, 1,
  24.      "R", &ParamSetReport, 1,
  25.      "S", &ParamSetSubDirs, 0,
  26.      "?", &ParamSetHelp, 1,
  27.      "H", &ParamSetHelp, 1,
  28.      "NOD", &ParamSetNoDefault, 0,
  29.      "TEST", &ParamSetTest, 0,
  30.      "Y", &ParamSetYes, 0,
  31.      "N", &ParamSetTest, 0,
  32.      "\0", NULL, 0
  33. } ;
  34.  
  35. ParamBlock params = {
  36.     "/-",   IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
  37.     pentry
  38. } ;
  39.  
  40. int main(int argc, char *argv[])
  41. {
  42. USHORT ret ;
  43. SEL ginfo, linfo ;
  44. GINFOSEG FAR *pgis ;
  45. int output ;
  46. unsigned long days, hours, minutes, seconds, hundredths ;
  47.  
  48.    progname = argv[0] ;
  49.    days = 0L ; hours = 0L ; minutes = 0L ; seconds = 0L ; hundredths = 0L ;
  50.    output = FALSE ;
  51.  
  52.    ParamHandle(¶ms, &argc, argv) ;
  53.  
  54.    if (pflags & PA_HELP )
  55.    {
  56.       printf("%s - displays the time the system has been up.\n", progname) ;
  57.       puts(VERSION) ;
  58.       printf("Usage: %s [/H | /? | /R ] command arguments\n", progname) ;
  59.       puts("Where:") ;
  60.       puts("      /R = Report mode   /H,/? = Help") ;
  61.       return( 0 ) ;
  62.    }
  63.  
  64.    if (( ret = DosGetInfoSeg(&ginfo, &linfo)) != 0)
  65.    {
  66.       printf("%s: error in DosGetInfoSeg", progname) ;
  67.       return(1) ;
  68.    }
  69.  
  70.    pgis = MAKEPGINFOSEG(ginfo) ;
  71.  
  72.    seconds = pgis->msecs / 1000 ;
  73.    minutes = seconds / 60 ;
  74.    hours = minutes / 60 ;
  75.    days = hours / 24 ;
  76.    hours -= days * 24 ;
  77.    minutes -= days*24*60 + hours * 60 ;
  78.    seconds -= days*24*60*60 + hours*60*60 + minutes*60 ;
  79.    hundredths -= days*24*60*60*1000 + hours*60*60*1000 + minutes*60*1000 + seconds*1000 ;
  80.  
  81.    if (pflags & PA_REPORT)
  82.    {
  83.       printf("[UPTIME]\ndays=%ld\nhours=%ld\nminutes=%ld\nseconds=%ld\n",
  84.           days, hours, minutes, seconds) ;
  85.    }
  86.    else
  87.    {
  88.       printf("The system has been up ") ;
  89.  
  90.       if (days != 0)
  91.       {
  92.      output = TRUE ;
  93.      printf("%ld days, ", days) ;
  94.       }
  95.  
  96.       if (hours != 0)
  97.       {
  98.      output = TRUE ;
  99.      printf("%ld hours, ", hours) ;
  100.       }
  101.  
  102.       if (minutes != 0 || output == TRUE)
  103.       {
  104.      output = TRUE ;
  105.      printf("%ld minutes, ", minutes ) ;
  106.       }
  107.  
  108.       if (seconds != 0 || output == TRUE)
  109.       {
  110.      output = TRUE ;
  111.      printf("%ld seconds.\n", seconds ) ;
  112.        }
  113.  
  114. //    printf("%ld hundredths.", hundredths ) ;
  115. //   printf("The system has been up %ul milliseconds\n", pgis->msecs) ;
  116.    }
  117.  
  118.    return( 0 ) ;
  119. }
  120.